package com.atguigu.mr.flow;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Partitioner;

/**
 * @description: 将手机号不同的输出到相应的分区中.
 * @create: 2019-12-15 22:06
 * @author: baojinlong
 **/
public class ProvincePartitioner extends Partitioner<Text, FlowBean> {
    @Override
    public int getPartition(Text text, FlowBean flowBean, int numPartitions) {
        // 1 获取电话号码的前三位
        String preNum = text.toString().substring(0, 3);
        int partition = 4;
        // 2 判断是哪个省
        switch (preNum) {
            case "136":
                partition = 0;
                break;
            case "137":
                partition = 1;
                break;
            case "138":
                partition = 2;
                break;
            case "139":
                partition = 3;
                break;
            default:
        }
        return partition;
    }
}
